from datetime import datetime
from typing import Optional

from fastapi_amis_admin.models import Field
from ..common import AppBaseModel, PageParams
from pydantic import BaseModel

class SysUser(AppBaseModel, table=True):
    __tablename__ = "sys_user"
    __table_args__ = {'extend_existing': True}
    username: Optional[str] = Field(nullable=False, index=True, title='用户名')
    password: Optional[str] = Field(title='密码')
    real_name: Optional[str] = Field(title='姓名',
                                     serialization_alias="realName", validation_alias="realName", alias="realName")
    head_url: Optional[str] = Field(title='头像',
                                    serialization_alias="headUrl", validation_alias="headUrl", alias="headUrl")
    gender: Optional[int] = Field(title='性别', description="性别   0：男   1：女    2：保密")
    email: Optional[str] = Field(title='邮箱')
    mobile: Optional[str] = Field(title='手机号')
    sort: Optional[int] = Field(title='排序')
    dept_id: Optional[int] = Field(title='部门ID',
                                   serialization_alias="deptId", validation_alias="deptId", alias="deptId")
    dept_ids: Optional[str] = Field(title='多个部门ids，逗号连接',
                                    serialization_alias="deptIds", validation_alias="deptIds", alias="deptIds")
    app_codes: Optional[str] = Field(title='绑定系统编码，多个逗号分隔',
                                     serialization_alias="appCodes", validation_alias="appCodes", alias="appCodes")
    role_ids: Optional[str] = Field(title='多个角色ids，逗号连接',
                                    serialization_alias="roleIds", validation_alias="roleIds", alias="roleIds")
    super_admin: Optional[int] = Field(title='超级管理员', description="超级管理员   0：否   1：是",
                                       serialization_alias="superAdmin", validation_alias="superAdmin", alias="superAdmin")
    status: Optional[int] = Field(title='状态', description="状态  0：停用   1：正常")
    open_id: Optional[str] = Field(title='微信openid',
                                   serialization_alias="openId", validation_alias="openId", alias="openId")
    login_failed_count: Optional[int] = Field(default=0, title='登录失败次数',
                                              serialization_alias="loginFailedCount", validation_alias="loginFailedCount", alias="loginFailedCount")
    login_failed_date: Optional[datetime] = Field(title='最后一次登录失败时间',
                                                  serialization_alias="loginFailedDate", validation_alias="loginFailedDate", alias="loginFailedDate")
    update_password_date: Optional[datetime] = Field(title='更新密码时间',
                                                     serialization_alias="updatePasswordDate", validation_alias="updatePasswordDate", alias="updatePasswordDate")

class UserQueryParams(PageParams):
    username: Optional[str] = Field(title="用户名")